Question 1
What are the process elements in a process control block (PCB)?
At any given point in time, while a process is in execution, it can be uniquely characterized by a number of elements, known as process elements.
These elements are:
- Identifier: A unique identifier associated with this process, distinguishing it from all other processes.
- State: The current state of the process (e.g., running, waiting).
- Priority: The priority level of the process relative to other processes.
- Program counter: The address of the next instruction to be executed.
- Memory pointers: Pointers to the program code and data, as well as memory blocks shared with other processes.
- Context data: Data present in processor registers while the process is executing.
- I/O status information: Information regarding outstanding I/O requests, assigned devices (e.g., tape drives), and files in use.
- Accounting information: Data such as processor time used, time limits, account numbers, etc.
Question 2
Draw the process state diagram depicting the five states that a process can be in.
The five states that a process can be in are:
- New: The process is being created.
- Running: Instructions are being executed.
- Waiting: The process is waiting for some event to occur.
- Ready: The process is ready and waiting to be assigned to a processor.
- Terminated: The process has finished execution.
Question 3
Describe the actions taken by a kernel to context-switch between processes.
When performing a context switch, the operating system must:
- Save the state of the currently running process, including the values of all CPU registers and memory allocations.
- Restore the state of the next process to be run.
- Perform architecture-specific operations, such as flushing data and instruction caches.
Question 4
Describe the differences among short-term, medium-term, and long-term scheduling.
- Short-term (CPU scheduler): Selects jobs that are ready to execute from memory and allocates CPU time to them.
It operates frequently to select the next process to run.
- Medium-term: Used primarily in time-sharing systems, this scheduler swaps processes in and out of memory to optimize system performance.
It is invoked less often than short-term scheduling.
- Long-term (job scheduler): Determines which jobs are brought into memory for processing.
This scheduler operates less frequently as it handles the placement of jobs in the system.
Question 5
What resources are used when a thread is created? How do they differ from those used when a process is created?
When a thread is created, fewer resources are required compared to creating a process. Specifically:
- Thread creation: Requires allocating a small data structure to hold the thread’s register set, stack, and priority.
- Process creation: Requires allocating a Process Control Block (PCB), a larger structure that includes a memory map,
list of open files, environment variables, and process-specific data.
Allocating and managing the memory map is often the most time-consuming part.
Question 6
What are the benefits of a multithreaded system?
Benefits of multithreading include:
- Increased responsiveness: Even if one thread is blocked, other threads can still execute.
- Resource sharing: Threads can share code and memory, improving resource efficiency.
- Economy: Creating threads uses fewer resources compared to creating separate processes.
- Taking advantage of multiprocessors: Threads can run in parallel on different processors, improving performance.
Question 7
Which of the following components of program state are shared across threads in a multithreaded process?
The components shared across threads are:
- Heap memory
- Global variables
Each thread has its own:
- Register values
- Stack memory
Question 8
Describe the actions taken by a kernel to context-switch between kernel-level threads.
Context switching between kernel-level threads typically involves:
- Saving the CPU register values of the thread being switched out.
- Restoring the CPU register values of the thread that is being scheduled next.
Question 9
What are two differences between user-level threads and kernel-level threads? Under what circumstances is one type better than the other?
- User-level threads: Are not recognized by the kernel and are scheduled by the thread library. They are lighter and less expensive to maintain.
- Kernel-level threads: Are managed by the kernel and are typically more expensive to maintain, as they require kernel data structures.
When each is better:
- User-level threads: Are better in situations where minimal kernel involvement is needed and where lightweight threading is crucial.
- Kernel-level threads: Are better when true multitasking and better integration with hardware resources are necessary.
Question 10
State three common ways of establishing a relationship between user threads and kernel threads.
Common models for establishing a relationship between user threads and kernel threads are:
1. Many-to-One Model: Multiple user threads are mapped to a single kernel thread.
2. One-to-One Model: Each user thread is mapped to a kernel thread.
3. Many-to-Many Model: Multiple user threads are mapped to multiple kernel threads.